<template>
  <wd-picker :columns="columns" :label="label" v-model="value" />
</template>

<script lang="ts" setup>
import { ref, defineProps, defineEmits } from 'vue'
import { getConfig } from '@/api/configApi'
const props = defineProps<{
  modelValue: any
  configName: string
  label?: string
}>()
const value = ref(props.modelValue)
watch(
  () => props.modelValue,
  newVal => {
    value.value = newVal
  },
  { deep: true }
)

watch(value, newVal => {
  emit('update:modelValue', newVal)
})
const emit = defineEmits(['update:modelValue'])
const columns = ref([])
const configs = getConfig()
configs.then(res => {
  let data = res.data[props.configName]
  columns.value = data.map(v => {
    return {
      label: v.name,
      value: v.code
    }
  })
})
</script>

<style lang="scss" scoped></style>
